package com.changgou.web.gateway.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.http.HttpCookie;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.stereotype.Service;

/**
 * @Author LQQ
 * @Date 2020/3/10 19:31
 * @Version 1.0
 */
@Service
public class AuthService {

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    //从cookie中获取jti的值
    public String GetJtiFromCookie(ServerHttpRequest request) {

        HttpCookie httpCookie = request.getCookies().getFirst("uid");

        if (httpCookie != null){
            String jti = httpCookie.getValue();
            return jti;

        }
        return null;
    }



    //从Redis中获取jwt的值
    public String getJwtFromRedis(String jti) {

        String jwt = stringRedisTemplate.boundValueOps(jti).get();

        if (jwt != null){
            return jwt;
        }
        return null;
    }
}
